package com.gvsoft.busi;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * ProjectName:gvMsgClient
 * Author: zhaoqiubo
 * Date: 15/8/13
 * Time: 下午5:46
 * Desc:
 */
public class MsgQueueConsumer extends Thread {
    private static Logger logger = LogManager.getLogger(MsgQueueConsumer.class.getName());
    public void run(){
        logger.info("短消息队列消费者线程启动……");
        while (true){

            try {
                MsgInfo msgInfo = new MsgInfo();
                msgInfo = (MsgInfo) MsgInfo.MQUEUE.poll(1, TimeUnit.SECONDS);
                if(msgInfo!=null){
                    handleMsgInfo(msgInfo);
                }else{
                    Thread.sleep(200);
                    logger.debug("短消息队列里面没有短消息，休息了一会儿……");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    private void handleMsgInfo(MsgInfo msgInfo){
        logger.debug("此处请客户端处理短消息"+msgInfo.toJsonStr());

    }
}
